<?php
include_once 'mysql_connect.php';
$infor=explode(',',$_GET['topic_infor']);
//获取IP	
function GetIP()
{ 
	if ($_SERVER["HTTP_X_FORWARDED_FOR"])
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	else if ($_SERVER["HTTP_CLIENT_IP"])
		$ip = $_SERVER["HTTP_CLIENT_IP"];
	else if ($_SERVER["REMOTE_ADDR"])
		$ip = $_SERVER["REMOTE_ADDR"];
	else if (getenv("HTTP_X_FORWARDED_FOR"))
		$ip = getenv("HTTP_X_FORWARDED_FOR");
	else if (getenv("HTTP_CLIENT_IP"))
		$ip = getenv("HTTP_CLIENT_IP");
	else if (getenv("REMOTE_ADDR"))
		$ip = getenv("REMOTE_ADDR");
	else
		$ip = "Unknown";
	return $ip;
}
///发帖
if(isset($_GET['u_tid']))
{
	$u_tid=explode(',',$_GET['u_tid']);
	$uid=$u_tid['0'];
	$tid=$u_tid['1'];
	$dateline=time();
	$content=$_POST['content'];
	$topics=mysql_query("SELECT `topics` FROM `bbs_member_infor` WHERE `uid`='$uid'");
	$topics=mysql_fetch_array($topics);
	$topics=$topics['topics']+1;
	$ip=GetIP();
	
	$tid_a=mysql_query("SELECT `tid` FROM `bbs_topic` ORDER BY `tid` DESC");
	$tid_a=mysql_fetch_array($tid_a);
	$tid_a=$tid_a['tid']+1;
	
	if(!empty($content))
	{	
		mysql_query("UPDATE `bbs_member_infor` SET `topics`='$topics' WHERE `uid`='$uid'");
		mysql_query("INSERT INTO `bbs_topic` (`tid`,`uid`,`dateline`,`father_tid`,`ip`) VALUES ('','$uid','$dateline','$tid','$ip') ");
		mysql_query("INSERT INTO `bbs_topic_content` (`tid`,`content`) VALUES ('$tid_a','$content')");

		$mess="$uid,$tid";
		header("location:topic.php?topic_infor=$mess");

	}
	else
	{
		$message="内容不能为空";
		header("location:show.php?show=$message");
	}
}


$infor=explode(',',$_GET['topic_infor']);
$uid=$infor['0'];//浏览人的ID
$tid=$infor['1'];//主题ID

$topic_infor=mysql_query("SELECT `uid`,`title`,`dateline`,`father_tid` FROM `bbs_topic` WHERE `tid`='$tid'");
$topic=mysql_fetch_array($topic_infor);
$title=$topic['title'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ;?>&nbsp;主题区</title>
</head>

<body><br /><hr /><br />
<table width="915" height="238" border="1">
  <tr>
    <td width="200" align="right"><font color="#6633CC">标题：</font></td>
    <td width="700"><font color="#6633CC"><?php echo $title;?></font></td>
  </tr>
<?php

$topic_output=mysql_query("SELECT `tid` FROM `bbs_topic` WHERE `father_tid`='$tid'");
while($row=mysql_fetch_array($topic_output))
{
	//while中的信息表示为 w_xxxx

	//father_tid旗下的所有tid
	$w_tid=$row['tid'];
	//查找内容
	$w_content=mysql_query("SELECT `content` FROM `bbs_topic_content` WHERE `tid`='$w_tid'");
	$w_content=mysql_fetch_array($w_content);
	$w_content=$w_content['content'];
	//查找回过贴的uid

	$w_uid_t=mysql_query("SELECT `uid`,`dateline` FROM `bbs_topic` WHERE `tid`='$w_tid' ");
	$w_uid_t=mysql_fetch_array($w_uid_t);
	$w_uid=$w_uid_t['uid'];
	//时间以亚洲上海为准
	date_default_timezone_set('Asia/Shanghai');//亚洲上海时区
	$w_time=$w_uid_t['dateline'];
	$w_time=date("Y-m-d G:i:s",$w_time);	
	//查找账号信息member_infor表
	$w_user_infor=mysql_query("SELECT `photo`,`topics`,`sex` FROM `bbs_member_infor` WHERE `uid`='$w_uid'");
	$w_user_infor=mysql_fetch_array($w_user_infor);
	$w_photo=$w_user_infor['photo'];
	$w_sex=$w_user_infor['sex'];
	$w_topics=$w_user_infor['topics'];
	//查找账号信息member表	
	$w_user_member=mysql_query("SELECT `class`,`username` FROM `bbs_member` WHERE `uid`='$w_uid'");
	$w_user_member=mysql_fetch_array($w_user_member);
	$w_username=$w_user_member['username'];
	$w_class=$w_user_member['class'];
	
	switch($w_class)
	{
		case 1: $w_classn='会员'; break;
		case 2: $w_classn='高级会员'; break;
		case 3: $w_classn='白金会员'; break;
		case 4: $w_classn='版主'; break;
		case 5: $w_classn='管理员'; break;
	}
	switch($w_sex)
	{
		case 1: $w_sexn="男生"; break;
		case 2: $w_sexn="女生"; break;
		case 3: $w_sexn="神仙"; break;
		case 4: $w_sexn="妖魔"; break;
		
	}

?>
  <tr>
    <td><img src="<?php echo $w_photo ;?>" width="80" height="80" /></td>
    <td rowspan="5"><?php echo $w_content;?></td>
  </tr>
  <tr>
    <td>UID:<font color="red"><?php echo $w_uid;?></font></td>
  </tr>
  <tr>
    <td>USER:<a href="my_zone.php?uid=<?php echo $w_uid ;?>"><font color="red"><?php echo $w_username;?></font></td>
  </tr>
  <tr>
    <td>身份:<font color="red"><?php echo $w_classn;?></font></td>
  </tr>
  <tr>
    <td>帖数:<font color="red"><?php echo $w_topics;?></font></td>
  </tr>
  <tr>
    <td>SEX:<font color="red"><?php echo $w_sexn;?></font></td>
    <td align="right"><font color="red"><?php echo $w_time;?></font></td>
  </tr>
<?php
}

?>
</table>
<form action="topic.php?u_tid=<?php echo $infor['0'].",".$tid ;?>" method="post">
<table width="916" border="1">
	<tr>		
		<td width="200" height="33"  valign="bottom" align="right"><input type="submit" name="oksub" value="发布" /></td>
   	 	<td width="700"><textarea cols="88" rows="10" name="content"></textarea></td>
	</tr>
	<tr>
		<td align="center" colspan="2"></td>
	</tr>
</table>
</form>
</body>
</html>
